<!DOCTYPE html>
<html>
    
    <head>
        <meta charset="utf-8">
        <title>X-admin v1.0</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <link rel="stylesheet" href="__PUBLIC__/X-admin/css/x-admin.css" media="all">
    </head>
    
    <body>
        <div class="x-body">
            <form class="layui-form" method="post" action="" >
            	<table class="layui-table" lay-skin="nob">
                       <tr>
                  
                          <td>
                            <label for="L_email" class="layui-form-label">班级名</label>
                          </td> 
                          <td>

                            <div class="layui-input-inline" style="width:120px;text-align: left">
                            <input type="text" name="classname" lay-verify="required" placeholder="请输入班级名称" autocomplete="off" class="layui-input">   
                            </div>  
                          </td>
                          <td>
                            <label for="L_email" class="layui-form-label">班主任</label>
                          </td> 
                          <td>
                            <div class="layui-input-inline" style="width:120px;text-align: left">
                            <select name="admin" lay-verify="required">
                                <option value='' >--请选择--</option>
                                <foreach name='admin' item='row'>
                                  <option value="{$row['id']}">{$row['name']}</option>
                                </foreach>
                            </select>    
                            </div>     
                          </td>
                        </tr>

                        <tr>
                          <td>
                            <label for="L_email" class="layui-form-label">讲师</label>
                          </td> 
                        
                          <td>
                            <div class="layui-input-inline" style="width:120px;text-align: left">
                            <select name="teacher" lay-verify="required">
                               <option value="">--请选择--</option>
                               <foreach name='teacher' item='row'>
                                  <option value="{$row['id']}">{$row['name']}</option>
                                </foreach>
                            </select>    
                            </div>  
                          </td>
                          <td>
                            <label for="L_email" class="layui-form-label">项目经理</label>
                          </td> 
                          <td>
                            <div class="layui-input-inline" style="width:120px;text-align: left">
                            <select name="pm" lay-verify="required">
                               <option value="" >--请选择--</option>
                               <foreach name='pm' item='row'>
                                  <option value="{$row['id']}">{$row['name']}</option>
                                </foreach>
                            </select>    
                            </div>     
                          </td>
                         
                        </tr>

                        <tr>
                        
                          <td>
                            <label for="L_email" class="layui-form-label">开班时间</label>
                          </td> 
                        
                          <td>
                            <div class="layui-input-inline" style="width:120px;text-align: left">
                             <input class="layui-input" lay-verify="required" name='start' placeholder="开始日" id="LAY_demorange_s">
                            </div>  
                          </td>

                          <td>
                            <label for="L_email" class="layui-form-label" >专业</label>
                          </td> 
                        
                          <td>
                            <div class="layui-input-inline" style="width:120px;text-align: left">
                            <select name="major" >
                              <option value='' >--请选择--</option>
                              <foreach name='major' item='row'>
                               <option value="{$row['id']}">{$row['name']}</option>
                             </foreach>
                            </select>    
                            </div>  
                          </td>
                          
                        </tr> 
                     
                        <tr>
                         <td>
                            <label for="L_email" class="layui-form-label">毕业时间</label>
                          </td>

                          <td>
                            <div class="layui-input-inline" style="width:120px;text-align: left">
                            <input class="layui-input" name='end' placeholder="截止日" id="LAY_demorange_e"> 
                            </div>     
                          </td>

                          <td>
                            <label for="L_email" class="layui-form-label">状态</label>
                          </td> 
                          <td>
                            <div class="layui-input-inline" style="width:120px;text-align: left">
                              <select name="status">
                                <option value="" >--请选择--</option>
                                <option value='0'>即将开班</option>
                                <option value='1'>正常上课</option>
                                <option value='2'>已毕业</option>
                              </select>    
                            </div>     
                          </td>
                        </tr>

                        <tr>
                          <td>
                            <label for="L_email" class="layui-form-label">教室</label>
                          </td> 
                        
                          <td>
                            <div class="layui-input-inline" style="width:120px;text-align: left">
                              <select name="classroom">
                                 <option value="">--请选择--</option>
                                 <foreach name='roomm' item='row'>
                                    <option value="{$row['id']}">{$row['name']}</option>
                                 </foreach>
                              </select>    
                            </div>  
                          </td>
                        </tr>
                </table>

                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label"></label>
                    <button  class="layui-btn" lay-filter="add" lay-submit="">添加</button>
                    <button  class="layui-btn" type="reset">重置</button>
                </div>
            </form>
        </div>
        <script src="__PUBLIC__/X-admin/lib/layui/layui.js" charset="utf-8">
        </script>
        <script src="__PUBLIC__/X-admin/js/x-layui.js" charset="utf-8">
        </script>
        <script>
            layui.use(['form','layer','laydate'], function(){
              $ = layui.jquery;
              var form = layui.form();
              var laydate = layui.laydate;
              layer = layui.layer;

              var start = {
                min: laydate.now()
                ,max: '2099-06-16 23:59:59'
                ,istoday: false
                ,choose: function(datas){
                  end.min = datas; //开始日选好后，重置结束日的最小日期
                  end.start = datas //将结束日的初始值设定为开始日
                }
              };
              
              var end = {
                min: laydate.now()
                ,max: '2099-06-16 23:59:59'
                ,istoday: false
                ,choose: function(datas){
                  start.max = datas; //结束日选好后，重置开始日的最大日期
                }
              };
              
              document.getElementById('LAY_demorange_s').onclick = function(){
                start.elem = this;
                laydate(start);
              }
              document.getElementById('LAY_demorange_e').onclick = function(){
                end.elem = this
                laydate(end);
              }
              //监听提交
              form.on('submit(add)', function(data){
                classname=$("input[name='classname']").val();
                admin=$("select[name='admin']").val();
                teacher=$("select[name='teacher']").val();
                pm=$("select[name='pm']").val();
                status=$("select[name='status']").val();
                classroom=$("select[name='classroom']").val();
                major=$("select[name='major']").val();
                start=$("input[name='start']").val();
                end=$("input[name='end']").val();
                // post方式添加
                $.post('__MODULE__/Classmanage/doadd',{classname:classname,admin:admin,teacher:teacher,pm:pm,status:status,classroom:classroom,major:major,start:start,end:end},function(data){
                    if(data=="添加成功"){
                        layer.alert("添加成功", {icon: 6},function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            parent.reload();
                        });
                    }else{
                        alert('数据添加失败');
                        return false;
                    }
                });

                    return false;
              });
            }); 
        </script>
    </body>

</html>